/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import business.RegisterMember;
import business.UserLogin;
import java.sql.*;
import java.util.*;

/**
 *
 * @author User
 */
public class LoginUserDBase extends ConnectionManager {

    public static boolean cekUser(String email, String pass) {
        Statement st = null;
        ResultSet rs = null;
        boolean x = false;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url + dbname, user, password);
            st = conn.createStatement();
            rs = st.executeQuery("SELECT nama_member FROM member where "
                    + "email='" + email + "' and password='" + pass+"'");
            if (rs.next()) {
                x = true;
            } else {
                x = false;
            }
        } catch (Exception e) {
        }
        return x;
    }

    public static boolean cekAdmin(String email, String pass) {
        Statement st = null;
        ResultSet rs = null;
        boolean x = false;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url + dbname, user, password);
            st = conn.createStatement();
            rs = st.executeQuery("SELECT nama_member FROM member where "
                    + "email='" + email + "' and password='" + pass + "' and role='administrator' ");
            if (rs.next()) {
                x = true;
            } else {
                x = false;
            }
        } catch (Exception e) {
        }
        return x;
    }

    public static UserLogin selectUser(String email, String pass) {
        UserLogin user = new UserLogin();
        Statement st = null;
        ResultSet rs = null;

        try {

            st = conn.createStatement();
            rs = st.executeQuery("SELECT nama_member FROM member where "
                    + "email='" + email + "' and password='" + pass+"'");

            if (rs.next()) {
                user.setEmail(rs.getString("email"));
                user.setPass(rs.getString("pass"));

            }
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static UserLogin selectAdmin(String email, String pass) {
        UserLogin user = new UserLogin();
        Statement st = null;
        ResultSet rs = null;

        try {

            st = conn.createStatement();
            rs = st.executeQuery("SELECT * FROM member where "
                    + "email='" + email + "' and password='" + pass + "' and role='administrator' ");

            if (rs.next()) {
                user.setEmail(rs.getString("email"));
                user.setPass(rs.getString("password"));

            }
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

   
}
